package cn.gdchent.springbootsecurity.enums;

/**
 * @Description: 返回值状态码
 * @Author: zrk
 * @Date: 2019/8/3
 */

public enum ResultStatusEnum {

    /**操作成功*/
    SUCCESS(200, "操作成功"),
    FAILED(500, "操作失败"),

    VALIDATE_FAILED(404, "参数检验失败"),
    UNAUTHORIZED(401, "暂未登录或token已经过期"),
    LOGIN_ERROR(403,"登陆错误，请重新登陆!"),
    UNlOGIN(201, "暂未登录"),
    ALREADY_LOGIN(202,"已经注册,请不要重复注册"),
    REGISTER_SUCCESS(200,"注册成功"),
    FORBIDDEN(403, "没有相关权限"),
    /**参数错误*/
    PARAM_INVALID(4001,"参数错误"),
    PARAMS_EMPTY(4002,"参数为空"),
    UPLOAD_SUCCESS(200,"上传文件成功"),
    UPLOAD_ERROR(302,"你已经上传过该应用了,请不要重复上传!"),

    FIND_DATA_ERROR(4003,"查询数据库数据为空"),
    FILE_EMPTY(301,"文件上传为空，请选择正确的文件"),
    USER_ALREADY(303,"用户已经存在"),

    /**操作失败*/
    ERROR(5001,"操作失败"),

    /**结果为空*/
    RESULT_EMPTY(5002,"返回结果为空")
    ;

    private Integer status;
    private String msg;

    ResultStatusEnum(String msg) {
        this.msg = msg;
    }

    ResultStatusEnum(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public Integer getStatus() {
        return status;
    }

    public String getMsg(){
        return msg;
    }

    public static String getMsgByStatus(Integer status){
        if(status == null){
            return "";
        }
        for(ResultStatusEnum resultStatusEnum : values()){
            if(resultStatusEnum.getStatus().equals(status)){
                return resultStatusEnum.getMsg();
            }
        }
        return "";
    }

}
